<?php

namespace app\adminabc\controller;

use think\Controller;
use think\captcha\Captcha;
use think\Request;

class Index extends Controller {
	function index() {
		if (session ( 'admin_id' ) > 0)
			$this->redirect ( url ( 'Main/index' ) );
		$this->assign ( 'title', "hello" );
		return $this->fetch ( 'index' );
	}
	function checkLogin() {
		$verify = $this->request->param ( 'verify' );
		$account = $this->request->param ( 'account' );
		$password = $this->request->param ( 'password' );
		// if (! captcha_check ( $verify )) {
		// echo json_encode ( array ('code' => 0,'msg' => '验证码错误' ) );
		// } else {
		$info = model ( 'User' )->getInfo ( array ([ 'account','=',$account ],[ 'password','=',md5 ( $password ) ] ) );
		if (count ( $info ) > 0) {
			session ( 'admin_id', $info ['id'] );
			session ( 'account', $info ['account'] );
			echo json_encode ( array ('code' => 99,'msg' => '登录成功','url' => url ( 'Main/index' ) ) );
		} else
			echo json_encode ( array ('code' => 1,'msg' => '账号密码有误' ) );
		// }
	}
	function logout() {
		session ( null );
		$this->redirect ( url ( 'Index/index' ) );
	}
	public function verify() {
		$captcha = new Captcha ();
		$captcha->codeSet = '0123456789';
		return $captcha->entry ();
	}
}
